package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.web.entity.table.ReadingStudentPunchTableDef;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.web.entity.ReadingStudentPunch;
import com.dingreading.cloud.web.mapper.ReadingStudentPunchMapper;
import com.dingreading.cloud.web.service.ReadingStudentPunchService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-11-14
 */
@Service
public class ReadingStudentPunchServiceImpl extends BaseServiceImpl<ReadingStudentPunchMapper, ReadingStudentPunch, ReadingStudentPunchTableDef> implements ReadingStudentPunchService {

    @Override
    protected ReadingStudentPunchTableDef getTable() {
        return ReadingStudentPunchTableDef.readingStudentPunch;
    }

    @Override
    public ReadingStudentPunch getStudentPunch(String studentUid, Integer itemNum) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.studentUid.eq(studentUid))
                .and(table.itemNum.eq(itemNum));

        return getMapper().selectOneByCondition(condition);
    }

    @Override
    public List<ReadingStudentPunch> getStudentPunchList(String studentUid) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.studentUid.eq(studentUid));

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.itemNum.asc());

        return getMapper().selectListByQuery(wrapper);
    }

}
